package com.corpgovernment.organization.dataloader.db;

import com.corpgovernment.organization.entity.db.MbOrgEmployeeOpenCardRecord;
import com.corpgovernment.organization.mapper.MbOrgEmployeeOpenCardRecordMapper;
import com.corpgovernment.organization.model.MbOrgEmployeeOpenCardRecordModel;
import com.ctrip.corp.obt.generic.utils.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import tk.mybatis.mapper.entity.Example;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author zl.cui
 * @date 2023/10/12
 */
@Component
public class EmployeeOpenCardRecordLoader {
    @Autowired
    private MbOrgEmployeeOpenCardRecordMapper mbOrgEmployeeOpenCardRecordMapper;

    public List<MbOrgEmployeeOpenCardRecordModel> getOpenCardRecordList(List<String> uidList){
        if (CollectionUtils.isEmpty(uidList)){
            return Collections.emptyList();
        }
        Example example = new Example(MbOrgEmployeeOpenCardRecord.class);
        example.createCriteria().andIn("platUid", uidList);
        List<MbOrgEmployeeOpenCardRecord> mbOrgEmployeeOpenCardRecordList = mbOrgEmployeeOpenCardRecordMapper.selectByExample(example);
        return mbOrgEmployeeOpenCardRecordList.stream()
                .map(this::convert)
                .collect(Collectors.toList());
    }

    private MbOrgEmployeeOpenCardRecordModel convert(MbOrgEmployeeOpenCardRecord record){
        MbOrgEmployeeOpenCardRecordModel model = new MbOrgEmployeeOpenCardRecordModel();
        model.setName(record.getName());
        model.setOpenCardUid(record.getOpenCardUid());
        model.setPlatUid(record.getPlatUid());
        model.setSupplierUid(record.getSupplierUid());
        model.setSubAccountId(record.getSubAccountId());
        model.setSubAccountName(record.getSubAccountName());
        model.setCorporateEntity(record.getCorporateEntity());
        model.setSetDefaultSendConfig(record.getSetDefaultSendConfig());
        return model;
    }
}
